package org.uva.streambuilder;

import java.applet.Applet;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Observable;
import java.util.Set;


public class MaxStreamModule extends StreamModule {

	HashMap<Observable, Double> values;
	
	public MaxStreamModule(Applet app, int x, int y) {
		super(app, x, y);
		this.defaultColor = new Color(233, 69, 243);
		this.selectColor = new Color(200, 20, 0, 200);
		this.name = "Max";
		
		values = new HashMap<Observable, Double>();
	}

	public void update(Observable o, Object arg) {
		if (arg instanceof Double)
		{
			Set<Observable> s = values.keySet();
			values.put(o, (Double) arg);
			Iterator<Observable> it = s.iterator();
			
			double max = 0;
			
			while (it.hasNext())
			{
				Object key = it.next();
				Object v = values.get(key);
				
				if (v instanceof Double)
				{
					if ((Double)v > max )
						max = (Double)v;
				}
				
			}
			
			setValue( max );
		}
	}
}
